package util

import (
	"os"
	"strconv"
)

func GetEnvOrDefault(key string, defaultValue string) string {
	value := os.Getenv(key)
	if value == "" {
		return defaultValue
	}
	return value
}

func GetEnvBool(key string) bool {
	value := os.Getenv(key)
	if value == "1" || value == "true" {
		return true
	}
	return false
}

func GetEnvIntOrDefault(key, defaultValue string) int {
	value := os.Getenv(key)
	if value == "" {
		int, err := strconv.Atoi(defaultValue)
		if err == nil {
			return int
		} else {
			return 0
		}
	}

	int, err := strconv.Atoi(value)
	if err == nil {
		return int
	} else {
		return 0
	}
}
